package cn.stylefeng.guns.modular.ctm.service.impl;

import cn.stylefeng.guns.modular.ctm.entity.ResumeFile;
import cn.stylefeng.guns.modular.ctm.mapper.ResumeFileMapper;
import cn.stylefeng.guns.modular.ctm.service.ResumeFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * <p>
 * 简历信息
 * </p>
 *
 * @author yzb
 * @since 2022-05-24
 */
@Service
public class ResumeFileServiceImpl extends ServiceImpl<ResumeFileMapper, ResumeFile> implements ResumeFileService {

    @Value("${file.baseResumeFilePath}")
    private String baseResumeFilePath;

    @Override
    public boolean remove(String id) throws IOException {
        boolean flag = false;
        ResumeFile resumeFile = baseMapper.selectById(id);
        if(ObjectUtils.isNotEmpty(resumeFile)){
            String path = baseResumeFilePath + "77d6d66479cb80fd1b70736a36a65912/" + resumeFile.getFileName();
            Files.delete(Paths.get(path));
            flag = this.removeById(id);
        }
        return flag;
    }
}
